package com.mh.service;

import com.mh.domain.Invoice;
import com.mh.domain.Item;
import com.mh.domain.Product;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/demo-mh-security-context.xml",
		"file:./resources/demo-mh-service-context.xml",
		"file:./resources/demo-mh-dao-context.xml",
		"file:./resources/demo-mh-web-context.xml" })
@Transactional
public class ItemServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected ItemService service;

	/**
	 * Instantiates a new ItemServiceTest.
	 *
	 */
	public ItemServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findItemByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findItemByPrimaryKey 
		Integer id = 0;
		Item response = null;
		response = service.findItemByPrimaryKey(id);
		// TODO: JUnit - Add assertions to test outputs of operation: findItemByPrimaryKey
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Item entity
	 * 
	 */
	@Test
	public void deleteItem() {
		// TODO: JUnit - Populate test inputs for operation: deleteItem 
		Item item = new com.mh.domain.Item();
		service.deleteItem(item);
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Invoice entity
	 * 
	 */
	@Test
	public void deleteItemInvoice() {
		// TODO: JUnit - Populate test inputs for operation: deleteItemInvoice 
		Integer item_id = 0;
		Integer related_invoice_id = 0;
		Item response = null;
		response = service.deleteItemInvoice(item_id, related_invoice_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteItemInvoice
	}

	/**
	 * Operation Unit Test
	 * Save an existing Item entity
	 * 
	 */
	@Test
	public void saveItem() {
		// TODO: JUnit - Populate test inputs for operation: saveItem 
		Item item_1 = new com.mh.domain.Item();
		service.saveItem(item_1);
	}

	/**
	 * Operation Unit Test
	 * Return a count of all Item entity
	 * 
	 */
	@Test
	public void countItems() {
		Integer response = null;
		response = service.countItems();
		// TODO: JUnit - Add assertions to test outputs of operation: countItems
	}

	/**
	 * Operation Unit Test
	 * Return all Item entity
	 * 
	 */
	@Test
	public void findAllItems() {
		// TODO: JUnit - Populate test inputs for operation: findAllItems 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Item> response = null;
		response = service.findAllItems(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllItems
	}

	/**
	 * Operation Unit Test
	 * Save an existing Product entity
	 * 
	 */
	@Test
	public void saveItemProduct() {
		// TODO: JUnit - Populate test inputs for operation: saveItemProduct 
		Integer id_1 = 0;
		Product related_product = new com.mh.domain.Product();
		Item response = null;
		response = service.saveItemProduct(id_1, related_product);
		// TODO: JUnit - Add assertions to test outputs of operation: saveItemProduct
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Product entity
	 * 
	 */
	@Test
	public void deleteItemProduct() {
		// TODO: JUnit - Populate test inputs for operation: deleteItemProduct 
		Integer item_id_1 = 0;
		Integer related_product_id = 0;
		Item response = null;
		response = service.deleteItemProduct(item_id_1, related_product_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteItemProduct
	}

	/**
	 * Operation Unit Test
	 * Load an existing Item entity
	 * 
	 */
	@Test
	public void loadItems() {
		Set<Item> response = null;
		response = service.loadItems();
		// TODO: JUnit - Add assertions to test outputs of operation: loadItems
	}

	/**
	 * Operation Unit Test
	 * Save an existing Invoice entity
	 * 
	 */
	@Test
	public void saveItemInvoice() {
		// TODO: JUnit - Populate test inputs for operation: saveItemInvoice 
		Integer id_2 = 0;
		Invoice related_invoice = new com.mh.domain.Invoice();
		Item response = null;
		response = service.saveItemInvoice(id_2, related_invoice);
		// TODO: JUnit - Add assertions to test outputs of operation: saveItemInvoice
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
